package lormi.meipin.controller.api;

import lormi.meipin.common.Result;
import lormi.meipin.controller.BaseController;
import lormi.meipin.dto.ChangePhoneDto;
import lormi.meipin.exception.LMException;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import javax.validation.constraints.NotNull;


/**
 * 用户管理
 * */
@RestController
@RequestMapping(value="v2",method=RequestMethod.POST,produces = "application/json; charset=utf-8")
public class MemberController extends BaseController{

	/**
	 * 改变密码
	 * userid 用户ID
	 * usertype 用户类型
	 * phone 新手机号
	 * code 新手机验证码
	 * */
	@RequestMapping("changephone")
	public String changePhone(@Valid ChangePhoneDto changePhoneDto,BindingResult result) throws LMException{
		checkResult(result);
		
		memberService.changePhone(changePhoneDto);
		return Result.success();
		
	}
	
	/**
	 * 获取用户名和头像地址
	 * @Param userid 用户ID
	 * @Param usertype 用户类型
	 * @Param listid 用户id  {12,13,14,15}
	 * */
	@RequestMapping("chat/photolist")
	@Valid
	public String getNameAndPhoto(@NotNull(message="100033") @RequestParam(value="listid",required=false) String listid) throws LMException{
		
		return Result.success(memberService.getMemberNameAndPhoto(listid));
	}
	
	/**
	 * 获取用户电话，并做业务处理
	 * @Param userid 用户ID
	 * @Param usertype 用户类型
	 * @Param telltoid 打电话对象ID
	 * */
	@Valid
	@RequestMapping("member/tellphone")
	public String getTellPhone(@NotNull(message="100033") @RequestParam(value="userid",required=false) Integer userid,
			@NotNull(message="100033") @RequestParam(value="usertype",required=false) Integer usertype,
			@NotNull(message="100033") @RequestParam(value="telltoid",required=false) Integer telltoid) throws LMException{
		
		return Result.success(memberService.getMemberPhone(userid, usertype, telltoid));
		
	}
	
}
